<style scoped lang="scss">
.account-password-main {
  display: flex;
  flex-direction: column;
  width: 400px;
  .title-description {
    padding-top: 0;
    margin-top: 0;
    margin-bottom: 40px;
    font-size: 0.9rem;
  }
}
.other-login-icon {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  .icon {
    cursor: pointer;
    margin: 0 3px;
    color: rgb( 91, 94, 96);
    font-size: 30px;
    padding: 7px;
  }
  .icon:hover{
    background-color: rgb(244,244,245);
    color: black;
    border-radius: 50%;
  }
}
</style>

<template>
  <div class="account-password-main">
    <h1>欢迎回来 👋🏻</h1>
    <p class="title-description">请输入您的帐户信息以开始管理您的项目</p>
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" size="medium">
      <el-form-item label="" prop="username">
        <el-input v-model.trim="loginForm.username" v-waves prefix-icon="el-icon-user-solid" clearable />
      </el-form-item>
      <el-form-item label="" prop="password">
        <el-input v-model.trim="loginForm.password" v-waves type="password" show-password prefix-icon="el-icon-lock" clearable />
      </el-form-item>
      <el-form-item label="">
        <div style="display: flex;flex-direction: row;justify-content: space-between;">
          <el-checkbox-group v-model="loginForm.remember">
            <el-checkbox label="1">记住账号</el-checkbox>
          </el-checkbox-group>
          <el-link type="primary" :underline="false" style="padding-bottom: 5px">忘记密码？</el-link>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button v-waves type="primary" style="width: 100%" @click="handleLogin">登录</el-button>
      </el-form-item>
      <el-form-item>
        <div class="" style="display: flex;flex-direction: row;justify-content: space-between;">
          <el-button v-waves plain style="width: 190px;" @click="$emit('switchLoginWay',2)">手机号登录</el-button>
          <el-button v-waves plain style="width: 190px;" @click="$emit('switchLoginWay',3)">扫码登录</el-button>
        </div>
      </el-form-item>
      <el-divider content-position="center">
        <span style="font-size: 0.75rem;">其他登录方式</span>
      </el-divider>
      <el-form-item>
        <div class="other-login-icon">
          <svg-icon icon-class="wechat" class="icon" style="font-size: 33px;" @click="clickWechatLogin" />
          <svg-icon icon-class="qq" class="icon" @click="clickQQLogin" />
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import md5 from 'js-md5'
export default {
  name: 'AccountPasswordLogin',
  data() {
    return {
      loginForm: {
        username: 'admin',
        password: '123456',
        remember: 0
      },
      loginRules: {
        username: [{ required: true, trigger: 'blur', message: '请输入账号' }],
        password: [{ required: true, trigger: 'blur', message: '请输入密码' }]
      }
    }
  },
  created() {
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          const data = {
            username: this.loginForm.username,
            password: md5(this.loginForm.password)
          }
          this.$store.dispatch('user/login', data)
            .then(() => {
              this.$router.push({ path: '/dashboard' })
              this.loading = false
              this.$notify({ title: '登录成功', message: `欢迎您回来！`, type: 'success', position: 'bottom-right' })
            })
            .catch(() => {
              this.loading = false
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    clickWechatLogin() {
      this.$message.warning('暂不支持【微信扫码登录】方式')
    },
    clickQQLogin() {
      this.$message.warning('暂不支持【QQ扫码登录】方式')
    }
  }
}
</script>

